//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_kickplayerbasefired.sqf"
#include "x_setup.sqf"

private "_num";
// TYRGHEN
__TRACE_1("_this","_this");
if (player in (list GVAR(player_base_trig))) then {
	private ["_ta","_muz","_var"];
	_ta = _this select 4;
	_muz = _this select 2;
	if (_ta isKindOf "TimeBombCore" || {getText(configFile/"CfgAmmo"/_ta/"simulation") in ["shotMine"]}) then {
		if (count _this > 6) then {
			deleteVehicle (_this select 6);
		};
		//TYRGHEN
		if ((serverCommandAvailable "#shutdown") || (if (isnil "mp_rights_fnc_hasRoles") then { false } else { (([] call mp_rights_fnc_isMember)) }) ) then {
			hint localize "STR_DOM_MISSIONSTRING_2007";
		} else {
			if (GVAR(kick_base_satchel) == 0) then {
				[QGVAR(p_f_b_k), [player, GVAR(name_pl),1]] call FUNC(NetCallEventCTS);
			} else {
				[QGVAR(p_bs), [player, GVAR(name_pl),1]] call FUNC(NetCallEventCTS);
			};
		};
	} else {
		//TYRGHEN
		// Modified the check for the zone, if a player is inside trigger2, no matter if there are enemies, he's kicked.
		__TRACE_2("",QGVAR(there_are_enemies_atbase),QGVAR(enemies_near_base))
		if (!GVAR(there_are_enemies_atbase) && {!GVAR(enemies_near_base)} && {!(getText(configFile/"CfgAmmo"/_ta/"simulation") in ["shotSmoke", "shotIlluminating", "shotNVGMarker", "shotCM", "shotSmokeX"])}) then {
			_num = __pGetVar(GVAR(p_f_b));
			__INC(_num);
			__pSetVar [QGVAR(p_f_b), _num];
			if ((serverCommandAvailable "#shutdown") || (if (isnil "mp_rights_fnc_hasRoles") then { false } else { (([] call mp_rights_fnc_isMember)) }) ) then {
				if (!GVAR(there_are_enemies_atbase) && {!GVAR(enemies_near_base)}) then {
					hint localize "STR_DOM_MISSIONSTRING_2007";
				};
			} else {
				// if the player is outside the safe zone, he can shoot, but will pay it.
				// Or if he's using a grenade, then we delete it.
				if ((player in (list GVAR(player_base_trig2))) 
					|| (_muz in ["HandGrenadeMuzzle","MiniGrenadeMuzzle","ThrowMuzzle"
						 ,"SmokeShellMuzzle","SmokeShellYellowMuzzle","SmokeShellRedMuzzle","SmokeShellGreenMuzzle","SmokeShellPurpleMuzzle","SmokeShellBlueMuzzle","SmokeShellOrangeMuzzle"
						 ,"UGL_F","GL_3GL_F"])) then {
					if (count _this > 6) then {
						deleteVehicle (_this select 6);
						#ifdef __DEBUG__
						_var = [(_this select 6),player in (list d_player_base_trig2)];
						__TRACE_1("Ammo Deleted","_var")
						#endif
					};
				};
				#ifdef __DEBUG__
				_var = [_num,__pGetVar(GVAR(pfbk_announced))];
				__TRACE_1("Shoot in base","_var")
				#endif
				if (GVAR(player_kick_shootingbase) != 1000) then {
					if (_num >= GVAR(player_kick_shootingbase)) then {
						if (isNil {__pGetVar(GVAR(pfbk_announced))}) then {
							[QGVAR(p_f_b_k), [player, GVAR(name_pl),0]] call FUNC(NetCallEventCTS);
							__pSetVar [QGVAR(pfbk_announced), true];
						};
					} else {
						hint (localize "STR_DOM_MISSIONSTRING_537");
					};
				} else {
					if (_num >= GVAR(player_kick_shootingbase)) then {
						[QGVAR(p_bs), [player, GVAR(name_pl),0]] call FUNC(NetCallEventCTS);
					};
				};
			};
		};
	};
} else {
	__pSetVar [QGVAR(p_f_b), 0];
};

// if !(serverCommandAvailable "#shutdown") then {
	// if (player in (list GVAR(player_base_trig))) then {
		// private "_ta";
		// _ta = _this select 4;
		// if (_ta isKindOf "TimeBombCore" || {getText(configFile >> "CfgAmmo" >> _ta >> "simulation") in ["shotMine"]} || {_ta == "ACE_PipebombExplosion"}) then {
			// if (count _this > 6) then {
				// deleteVehicle (_this select 6);
			// };
			// if (GVAR(kick_base_satchel) == 0) then {
				// [QGVAR(p_f_b_k), [player, GVAR(name_pl),1]] call FUNC(NetCallEventCTS);
			// } else {
				// [QGVAR(p_bs), [player, GVAR(name_pl),1]] call FUNC(NetCallEventCTS);
			// };
		// } else {
			// if (!GVAR(there_are_enemies_atbase) && {!GVAR(enemies_near_base)} && {!(getText(configFile >> "CfgAmmo" >> _ta >> "simulation") in ["shotSmoke", "shotIlluminating", "shotNVGMarker", "shotCM", "shotSmokeX"])}) then {
				// _num = __pGetVar(GVAR(p_f_b));
				// __INC(_num);
				// __pSetVar [QGVAR(p_f_b), _num];
				// if !(player in (list GVAR(player_base_trig2))) then {
					// if (GVAR(player_kick_shootingbase) != 1000) then {
						// if (_num >= GVAR(player_kick_shootingbase)) then {
							// if (isNil {__pGetVar(GVAR(pfbk_announced))}) then {
								// [QGVAR(p_f_b_k), [player, GVAR(name_pl),0]] call FUNC(NetCallEventCTS);
								// __pSetVar [QGVAR(pfbk_announced), true];
							// };
						// } else {
							// hint (localize "STR_DOM_MISSIONSTRING_537");
						// };
					// } else {
						// if (_num >= GVAR(player_kick_shootingbase)) then {
							// [QGVAR(p_bs), [player, GVAR(name_pl),0]] call FUNC(NetCallEventCTS);
						// };
					// };
				// };
			// };
		// };
	// } else {
		// __pSetVar [QGVAR(p_f_b), 0];
	// };
// };